package com.bjtu.laorenyouhao.guanliyuan.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.Query;

import com.bjtu.laorenyouhao.guanliyuan.dao.RoomDao;
import com.bjtu.laorenyouhao.guanliyuan.entity.RoomEntity;
import com.bjtu.laorenyouhao.guanliyuan.service.RoomService;
import org.springframework.util.StringUtils;


@Service("roomService")
public class RoomServiceImpl extends ServiceImpl<RoomDao, RoomEntity> implements RoomService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String key = (String) params.get("key");
        QueryWrapper<RoomEntity> queryWrapper = new QueryWrapper<RoomEntity>();
        if (StringUtils.hasLength(key)){
            queryWrapper.eq("id",key)
                    .or().like("name",key);
        }

        IPage<RoomEntity> page = this.page(
                new Query<RoomEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}